//
//  UIButton+Extension.swift
//  Weibo_SwiftDemo
//
//  Created by gjh on 2020/12/27.
//

import UIKit

extension UIButton {
    
    /// 初始化 button
    /// - Parameters:
    ///   - title: 名称
    ///   - titleColor: 颜色
    ///   - highlightColor: 高亮颜色
    ///   - backgroundImageName: 背景图片
    ///   - fontSize: 字体大小
    ///   - target: Target
    ///   - action: action
    convenience init(title: String, titleColor: UIColor, highlightColor: UIColor, backgroundImageName: String, fontSize: CGFloat, target: Any?, action: Selector) {
        
        self.init()
        setTitle(title, for: .normal)
        setTitleColor(titleColor, for: .normal)
        setTitleColor(highlightColor, for: .highlighted)
        titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
                
        setImage(UIImage(named: backgroundImageName), for: .normal)
        setImage(UIImage(named: backgroundImageName + "_highlighted"), for: .highlighted)
        addTarget(target, action: action, for: .touchUpInside)
        
    }
    /// 初始化 button
    /// - Parameters:
    ///   - title: 名称
    ///   - titleColor: 颜色
    ///   - highlightColor: 高亮颜色
    ///   - backgroundImageName: 背景图片
    ///   - fontSize: 字体大小
    convenience init(title: String, titleColor: UIColor, highlightColor: UIColor, backgroundImageName: String, fontSize: CGFloat) {
        
        self.init()
        setTitle(title, for: .normal)
        setTitleColor(titleColor, for: .normal)
        setTitleColor(highlightColor, for: .highlighted)
        titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
                
        setImage(UIImage(named: backgroundImageName), for: .normal)
        setImage(UIImage(named: backgroundImageName + "_highlighted"), for: .highlighted)
    }
}
